'''
Created on Oct 6, 2011

@author: anupam saini
'''
from multiprocessing import Process, cpu_count
import multiprocessing
from  multiprocessing import Queue
import os

home_folder = os.path.expanduser('~')

## for a good queue implementation check out this site.
## http://b.atcg.us/blog/2009/12/19/python-multiprocessingjoinablequeue-example.html
class MyWorker(Process):
    
    def __init__(self,q):
        Process.__init__(self)
        self.msg_queue= q

    def run(self):
        print 'cpu count : ',cpu_count()
        out =  'do nothing', os.getpid()
        self.msg_queue.put(out)

if __name__ == '__main__':

    output_que = Queue()
    for i in xrange(2):
        j = MyWorker(output_que)
        j.start()

    file_handle = None
    try:
        file_handle = open((home_folder + '/data'),'a')
        data = output_que.get()
        print data
        file_handle.write(str(data))
    finally:
        if file_handle:
            file_handle.close()